package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.TotalInfo;
import com.olddriver.crm.mapper.TotalInfoMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.QueryObject;
import com.olddriver.crm.service.ITotalInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class TotalInfoServiceImpl implements ITotalInfoService{

    @Autowired
    private TotalInfoMapper totalInfoMapper;

    @Override
    public int insert(TotalInfo totalInfo){
        return totalInfoMapper.insert(totalInfo);
    }

    @Override
    public int update(TotalInfo totalInfo){
        return totalInfoMapper.updateByPrimaryKey(totalInfo);
    }

    @Override
    public List<TotalInfo> listAll() {
        return totalInfoMapper.selectAll();
    }

    @Override
    public PageResult query(QueryObject qo) {
        int total = totalInfoMapper.queryTotal(qo);
        if (total == 0) {
            return new PageResult(total, Collections.emptyList());
        }
        return new PageResult(total, totalInfoMapper.queryRows(qo));
    }

}
